package com.sharekitchen.mapper;

import com.sharekitchen.entity.Admin;
import com.sharekitchen.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Mapper
@Transactional
public interface UserMapper {
    //    查找user是否存在
    @Select("SELECT COUNT(*)>0 FROM `user` WHERE username=#{username} AND is_delete=0")
    Boolean existUsername(String username);

    //    添加user
    @Insert("INSERT INTO `user`(username, password, user_money, create_time) VALUES(#{username}, #{password}, #{userMoney}, #{createTime})")
    int addUser(User user);

    //    获取user的信息
    @Select("SELECT * FROM `user` WHERE username=#{username}  AND is_delete=0 ")
    User findUserByName(String username);

    //    获取所有user的信息
    @Select("SELECT * FROM `user` WHERE is_delete=0 ")
    List<User> findAllUser();

    @Update("UPDATE `user` SET `is_delete`=1 WHERE username=#{username} AND is_delete=0")
    Boolean deleteUserByName(String username);

}
